'use strict';

function compute_chain_median(collection) {
  let temp =collection.split("->");
  let average;
  
  for (let i=0;i<temp.length;i++)
    {
      temp[i]=parseInt(temp[i]);
    }
    function sortNumber(a,b)
    {   
        return a -b ;
    }
    temp.sort(sortNumber);
  if(temp.length%2==0)
    {
      average=(temp[temp.length/2-1]+temp[temp.length/2+1-1])/2;
    }
  else 
    {
      average=temp[(temp.length+1)/2-1];
    }
  return average;
}

module.exports = compute_chain_median;
